package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;
//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressBookCtr
{
    
    private AdressBook ab;
   
   
    public AddressBookCtr()
    {
        ab = AdressBook.getInstance();
    }
    
    public Person getPerson(int id)
    {
        
        Person found = ab.findPerson(id);
        return found;
    }
    
    public void createPerson(int id, String name, String adress, int postalCode, String city, int phone)
    {   
       Person p = new Person(id, name, adress, postalCode, city, phone);
       ab.addPerson(p);
    }
    
    public void deletePerson(int id)
    {
        Person delete = getPerson(id);
        ab.deletePerson(delete);
    }
 
    
    public void updatePerson(int number, String character, int choise, int id)
    {
        Person p = getPerson(id);
        
        if (choise == 1) {
            int newId = number;
            p.setPersonId(newId);
        }
        
        if (choise == 2) {
            String newName = character;
            p.setPersonName(newName);
        }
        
        if (choise == 3) {
            String newAdress = character;
            p.setPersonAdress(newAdress);
        }
        
        if (choise == 4) {
            int newZipCode = number;
            p.setPersonZipCode(newZipCode);
        }
        
        if (choise == 5) {
            String newCity = character;
            p.setPersonCity(newCity);
        }
        
        if (choise == 6) {
            int newTlf = number;
            p.setPersonTlf(newTlf);
        }
        
    }
    
    public ArrayList<Person> listAllPersons()
    {
        
        return ab.getAll();
    }
}
